import os

from .ImageShop import ImageShop as Is


def pa(pstr):
    l = pstr.split(",")
    if len(l) == 1:
        return l[0],
    elif len(l) == 3:
        return l[0], (int(l[1]), int(l[2]))


class TestImageShop:
    """
    测试类
    """

    def __init__(self):
        """
        Instance Initialize.
        """
        while True:
            _input = input("请输入输入路径：\n")
            if os.path.isdir(_input) or os.path.isfile(_input):
                break
            else:
                print("请输入有效的路径！")
        self._input = _input

        output = input("请输入输出路径：（默认为output）\n")
        if output == "":
            output = "output"
        self._output = output

        params = []
        p = input("请输入必要的操作：\n")
        params.append(pa(p))
        while True:
            p = input("请输入操作，输入q跳过：\n")
            if p == "q":
                break
            else:
                params.append(pa(p))
        self._params = params

        in_type = input("请输入输入格式：（若输入为目录，请勿置空，默认为jpg）\n")
        if in_type == "":
            in_type = "jpg"
        self._in_type = in_type

        out_type = input("请输入输出格式：（默认为jpg）\n")
        if out_type == "":
            out_type = "jpg"
        self._out_type = out_type

    def test(self):
        """
        测试方法
        """
        i = Is(self._input, self._in_type)
        i.load_images()
        i.batch_ps(*self._params)
        i.display(3, 3, (150, 150))
        i.save(self._output, self._out_type)


if __name__ == "__main__":

    # 初始化测试用例
    t1 = TestImageShop()

    # 进行测试
    t1.test()
"""
Resource

FindEdges
q

gif
"""
"""
Resource/2.jpeg
output1/2.gif
Blur
Resize,130,200
q



"""
